using System;

namespace NET.Library.Web
{
	/// <summary>
	/// Class Name : JavaScript
	/// Author     : Martin Tomkins
	/// Synopsis   : Class used for returning client-side Javascript.
	/// </summary>
	public class JavaScript
	{
		const string beginScript = "<script language=\"javascript\">\n", endScript = "\n</script>\n";
/// <summary>
/// 
/// </summary>
		public JavaScript()
		{
			//
			// TODO: Add constructor logic here
			//
		}

		/// <summary>
		/// *************************************************************************
		/// * Name        : GoBack method
		/// * Description : Returns client-side javascript code as a string to 
		/// *             : navigate a specified number of steps back through the 
		/// *             : client's browser history .
		/// * Syntax      : Resp = GoBack(printBack)
		/// *************************************************************************/
		/// </summary>
		/// <remarks></remarks>
		/// <example>Response.Write (GoBack(1));</example>
		public static string GoBack(int Back)
		{
			string strScript = beginScript +
				"window.history.back(-" + Back.ToString() + ");" +
				endScript;
			return strScript;
		}
		/// <summary>
		/// 
		/// </summary>
		/// <param name="URL">URL to navigate to</param>
		/// <returns></returns>
		public static string Navigate(string URL)
		{
			string strScript = beginScript +
				"window.navigate('" + URL + "');" +
				endScript;
			return strScript;
		}
	
		/// <summary>
		/// 
		/// </summary>
		/// <param name="Message">Alert message</param>
		/// <param name="URL">URL to navigate to after displaying alert</param>
		/// <returns></returns>
		public static string NavigateMsg(string Message, string URL)
		{
			string strScript = beginScript +
				"window.alert('" + Message + "');\n" +
				"window.location.href='" + URL + "';" +
				endScript;
			return strScript;
		}
		/// <summary>
		/// 
		/// </summary>
		/// <param name="Message">Alert message</param>
		/// <param name="Back">Number of pages to go back in browser's history</param>
		/// <returns></returns>
		public static string GoBackMsg(string Message, int Back)
		{
			string strScript = beginScript +
				"window.alert('" + Message + "');\n" +
				"window.history.back(-" + Back + ");" +
				endScript;
			return strScript;
		}
		/// <summary>
		/// 
		/// </summary>
		/// <param name="Message"></param>
		/// <returns></returns>
		public static string GoBackMsg(string Message)
		{
			string strScript = beginScript +
				"window.alert('" + Message + "');\n" +
				"window.history.back(-1);" +
				endScript;
			return strScript;
		}
		/// <summary>
		/// 
		/// </summary>
		/// <param name="Message">Alert message</param>
		/// <returns></returns>
		public static string MsgBox(string Message)
		{
			string strScript = beginScript +
				"window.alert('" + Message + "');" +
				endScript;
			return strScript;
		}
		/// <summary>
		/// 
		/// </summary>
		/// <param name="URL">URL of page to open (can be relative or absolute)</param>
		/// <param name="Frame">Frame name to open page in</param>
		/// <returns></returns>
		public static string OpenPage(string URL, string Frame)
		{
			string strScript = beginScript +
				"window.open('" + URL + "','" + Frame + "');" +
				endScript;
			return strScript;
		}
		/// <summary>
		/// 
		/// </summary>
		/// <returns></returns>
		public static string ReloadPage()
		{
			string strScript = beginScript +
				"window.location.reload(true);" +
				endScript;
			return strScript;
		}
		/// <summary>
		/// 
		/// </summary>
		/// <param name="LoginPage"></param>
		/// <param name="ReturnUrl"></param>
		/// <returns></returns>
		public static string LoginPage(string LoginPage, string ReturnUrl)
		{
			string strScript = beginScript +
				"window.location=\"" + LoginPage + "?returnUrl=" +
				ReturnUrl + "\"" + ";" +
				endScript;
			return strScript;
		}
	}
}